package instrumentation;

import java.io.Serializable;
import java.io.File;
import java.io.FileWriter;
import java.util.Set;
import java.util.HashSet;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
public class ConditionClass implements Serializable{
	private static final long serialVersionUID = 6039856116509927723L;
	private final String cName;
	private final Set<Data> fields;
	private final Set<Condition> conditions;

	public ConditionClass(String cName, Set<Data> fields) {
		this.cName = cName;
		this.fields = fields;
		conditions = new HashSet<Condition>();
	}
	public String getCName(){
		return this.cName;
	}
	void addCondition(Condition c) {
		conditions.add(c);
	}
	public Set<Condition> getCondition() {
		return conditions;
	}

	public void write(File baseDir,String cName) {
		ObjectOutput oo = null;
		try {

			final File file = new File(baseDir, cName.replace('.', File.separatorChar) + ".wgz");
			oo = new ObjectOutputStream(new GZIPOutputStream(new FileOutputStream(file)));
			oo.writeObject(this);
		} catch(IOException e) {
		} finally {
			if(oo != null)
				try {
					oo.close();
				} catch(IOException e) {
				}
		}
	}

}
